package bTree.LeetCode;

public class 和为K的子数组 {
    int num = 0;
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;
        int[] preSum = new int[len+1];
        for (int i = 0; i < len; i++) {
            preSum[i + 1] = preSum[i] + nums[i];
        }
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j <= len; j++) {
                if (preSum[j] - preSum[i] == k) {
                    num++;
                }
            }
        }
        return num;
    }
}

